﻿<!DOCTYPE html >
<%! from apps.cm import SmManager%>

<html>
<head>
<title>产品管理</title>
<meta charset="UTF-8">
<%include file="../common/init.html" />
<%
from apps.cm import SmManager
loginUser = SmManager.getLoginUserID(request)
tree = u'<tr><a id="logout-btn" href="/logout/" class="easyui-linkbutton">退出登录</a></tr>'
%>
% if not loginUser:
<script>alert('请登录');window.location.href='/login/'</script>

% else:

<style type="text/css">
.label {
	FONT-SIZE: 14px;
	LINE-HEIGHT: 28px;
	text-align: right;
	width:100px;
}
#ff table tr th{color:red; border-bottom:1px solid #666666;}
</style>
</head>
<body class="easyui-layout">
	<div data-options="region:'center'" class="easyui-layout">
		<!-- 查询面板 -->
		<div class="easyui-panel" 
		    style="width:100%;height:150px;padding:10px;"
			data-options="iconCls:'icon-search',closable:false,region:'north',title:'产品管理'">
			<table>
                <!--
                <tr><a id="logout-btn" href="/logout/" class="easyui-linkbutton" data-options="iconCls:'icon-search'">退出登录</a></tr>
                -->
                ${tree}
                <tr>
                    <td class="label">产品名称:</td>
                    <!-- 
                    <td><input id="search_product_name" class="easyui-combobox" type="text" style="width:200px;" data-options="disabled:false"></input></td>
                   	 -->
                    <td><select id="search_product_id" class="easyui-combobox" style="width:200px;" data-options="valueField:'product_id',textField:'product_name',editable:true"></select></td>
                	<td><a id="search_btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a></td>
                    <form method="post" id="file_form" enctype="multipart/form-data" >
                        <td><a id="export_btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">导出Excel</a></td>
                        <td><P id="MyFile"><input type="file" name="fileImport" id="fileImport"  style="width:330px;" onchange="fileSelected();" /></P></td>
                        <td><a id="upload_btn" href="#" class="easyui-linkbutton" data-options="">上传</a></td>
                        <td><a id="download_btn" href="#" class="easyui-linkbutton" data-options="">下载</a></td>
                        <td><a id="sendemail_btn" href="#" class="easyui-linkbutton" data-options="">发送邮件</a></td>
                    </form>
                </tr>
			</table>
		</div>

		<!-- 查询表格 -->
		<div class="easyui-panel"  data-options="closable:false,region:'center',title:''">
		<table id="dg" class="easyui-datagrid"
			style="width:100%;height:100%;"
			data-options="rownumbers:true,singleSelect:true,
				url:'/cm/cmProductInfoAction!queryListJson.do',method:'get',
				toolbar:toolbar,pagination:true,pageSize:10,pageList:[10,20,50]">
			<thead>
				<tr>
				    <th data-options="field:'product_id',width:80,sortable:true" style="display:none">产品编号</th>
                    <th data-options="field:'product_name',width:120,sortable:true">产品名称</th>
                    <th data-options="field:'manager_id',width:120,sortable:true">产品经理</th>
                    <th data-options="field:'size_',width:120,sortable:true">产品规模</th>
                    <th data-options="field:'status',width:120,sortable:true">产品状态</th>
                    <th data-options="field:'create_date',width:150,sortable:true">创建时间</th>
                    <th data-options="field:'trade_manager_id',width:150" style="display:none">交易主管</th>
                    <th data-options="field:'risk_manager_id',width:150" style="display:none">风控专员</th>
                    <th data-options="field:'transfer_id',width:150" style="display:none">划拨专员</th>
                    <th data-options="field:'accounting_id',width:150" style="display:none">会计</th>
                    <th data-options="field:'sh_a_account',width:120" style="display:none">上海A股账户</th>
                    <th data-options="field:'sz_a_account',width:120" style="display:none">深圳A股账户</th>
                    <th data-options="field:'money_account',width:120" style="display:none">资金账户</th>
                    <th data-options="field:'account_passwd',width:120" style="display:none">资产账户密码</th>
                    <th data-options="field:'fee_rate',width:120" style="display:none">手续费率</th>

                    <th data-options="field:'_operate',width:260,align:'center',formatter:formatOper">操作</th>
				</tr>
			</thead>
		</table>
		</div>
	</div>

	<div id="dlg_addSize_" class="easyui-dialog" title="新增规模"
		style="width:300px;height:130px;padding:10px;"
		data-options="
				modal:true,
				iconCls: 'icon-save',
				toolbar: '',
				buttons: [{
					text:'确认',
					width:'70px',
					margin:'100px',
					iconCls:'icon-ok',
					handler: add_money,
				},{
					text:'取消',
					handler:function(){
					    closeAddSize_Form();
					}
				}]
			">
			
		<form id="addSize_" method="get" >
			<label>新增金额(万):</label>
			<input class="easyui-numberbox"/>
		</form>
	</div>
	
	<div id="dlg_removeSize_" class="easyui-dialog" title="减少规模"
		style="width:300px;height:130px;padding:10px;"
		data-options="
				modal:true,
				iconCls: 'icon-save',
				toolbar: '',
				buttons: [{
					text:'确认',
					width:'70px',
					margin:'100px',
					iconCls:'icon-ok',
					handler:remove_money,
				},{
					text:'取消',
					handler:function(){
					    closeRemoveSize_Form();
					}
				}]
			">
		
		<form id="removeSize_" method="get">
			<label>减少金额(万):</label>
			<input class="easyui-numberbox"/>
		</form>
	</div>

    <div id="dlg_sendEmail_" class="easyui-dialog" title="发送邮件"
		style="width:500px;height:350px;padding:10px;"
		data-options="
				modal:true,
				iconCls: 'icon-save',
				toolbar: '',
				buttons: [{
					text:'确认',
					width:'70px',
					margin:'100px',
					iconCls:'icon-ok',
					handler: send_email,
				},{
					text:'取消',
					handler:function(){
					    closeSendEmail_form();
					}
				}]
			">

		<form id="sendEmail_" method="post" enctype="multipart/form-data">
			<table>
            <tr>
            <td><label>收件人地址:</label></td>
			<td><input name="destaddress" class="easyui-textbox"/></td>
            </tr>
            <tr>
            <td><label>邮件主题:</label></td>
            <td><input name="subject" class="easyui-textbox"/></td>
            </tr>
            <tr>
            <td><label>邮件内容:</label></td>
            <td><input name="body" class="easyui-textbox" data-options="multiline:true" style="width:200px;height:100px"/></td>
            </tr>
            <tr>
                <td><label>附件:</label></td>
                <td><P id="fujian"><input type="file" name="fujianimport" id="fujianimport"  style="width:330px;" onchange="fileSelected();" /></P></td>
            </tr>
            </table>

		</form>
	</div>
	<!-- 新增和修改  对话框-->
	<div id="dlg_add" class="easyui-dialog" title="新增和修改"
		style="width:1000px;height:420px;padding:0px 10px;"
		data-options="
				modal:true,
				iconCls: 'icon-save',
				toolbar: '',
				buttons: [{
					text:'确认',
					width:'70px',
					margin:'100px',
					iconCls:'icon-ok',
					handler:function(){
					    submitForm();
					}
				},{
					text:'取消',
					handler:function(){
					    closeForm();
					}
				}]
			">

		<div style="margin:0px 0;"></div>
		<div>
			<form id="ff" method="get">
				<table cellpadding="5">
					<tr><th colspan="6">基础信息</th></tr>
                    <tr>
                        <td class="label">产品名称:</td>
                        <td><input id="product_name" name="formobj.product_name" class="easyui-textbox" type="text" style="width:200px;" data-options="required:true" /></td>
                        <td class="label">产品状态:</td>
                        <td><select id="status" name="formobj.status"  class="easyui-combobox" style="width:200px;" data-options="valueField:'item_value',textField:'item_cn',required:true,panelHeight:'auto'"></select></td>
                        <td class="label">产品经理:</td>
                        <td><input id="manager_id" name="formobj.manager_id" class="easyui-textbox" type="text" data-options="required:true,editable:true,icons: [{iconCls:'icon-add',handler: selectManager}]" style="width:200px;" /></td>
                    </tr>
                    <tr>
                        <td class="label">产品规模(万):</td>
                        <td><input id="size_" name="formobj.size_" class="easyui-numberbox"  type="text" style="width:200px;" data-options="required:false" /></td>
                    </tr>
                 </table>
                 <table cellpadding="5">
					<tr><th colspan="6">管理人员</th></tr>
                    <tr>
                        <td class="label">交易主管:</td>
                        <td><input id="trade_manager_id" name="formobj.trade_manager_id" class="easyui-textbox" type="text" data-options="required:true,icons: [{iconCls:'icon-add',handler: selectTradeManager}]" style="width:200px;"></td>
                        <td class="label">风控专员:</td>
                        <td><input id="risk_manager_id" name="formobj.risk_manager_id" class="easyui-numberbox" type="text" data-options="required:true,icons: [{iconCls:'icon-add',handler: selectRiskManager}]" style="width:200px;"></td>
                        <td class="label">划拨专员:</td>
                        <td><input id="transfer_id" name="formobj.transfer_id" class="easyui-numberbox" type="text" data-options="required:true,icons: [{iconCls:'icon-add',handler: selectTransferManager}]" style="width:200px;"></td>
                    </tr>
                    <tr>
                        <td class="label">会计:</td>
                        <td><input id="accounting_id" name="formobj.accounting_id" class="easyui-numberbox" type="text" data-options="required:true,icons: [{iconCls:'icon-add',handler: selectAccounting}]" style="width:200px;"></td>
                    </tr>
                 </table>
                 <table cellpadding="5">
					<tr><th colspan="6">账户信息</th></tr>
                    <tr>
                        <td class="label">上海A股账户:</td>
                        <td><input id="sh_a_account" name="formobj.sh_a_account" class="easyui-numberbox" type="text" data-options="required:true" style="width:200px;"></td>
                        <td class="label">深圳A股账户:</td>
                        <td><input id="sz_a_account" name="formobj.sz_a_account" class="easyui-numberbox" type="text" data-options="required:true" style="width:200px;"></td>
                        <td class="label">资金账户:</td>
                        <td><input id="money_account" name="formobj.money_account" class="easyui-numberbox" type="text" data-options="required:true" style="width:200px;"></td>
                    </tr>
                    <tr>
                        <td class="label">资产账户密码:</td>
                        <td><input id="account_passwd" name="formobj.account_passwd" class="easyui-textbox" type="password" style="width:200px;height:20px" data-options="required:true" /></td>
                    	<td class="label">手续费率:</td>
                        <td><input id="fee_rate" name="formobj.fee_rate" class="easyui-numberbox" type="text" style="width:200px;" data-options="required:true,min:0,precision:2" /></td>
                    </tr>
                 </table>
				<input type="hidden" name="formobj.product_id" id="product_id" />
			</form>
		</div>
	</div>
	
	<div id="dlg_addPerson"class="easyui-dialog" title="选择管理人" data-options="modal:true,region:'center'">
		<table id="dg_user" class="easyui-datagrid"
			style="width:320px;height:350px;"
			data-options="singleSelect:true">
			<thead>
				<tr>
					<th data-options="field:'user_id',width:120" style="">用户编号</th>
					<th data-options="field:'user_name',width:120">用户名称</th>
                    <th data-options="field:'_operate',width:40,align:'center',formatter:formatUserOper">操作</th>
				</tr>
			</thead>
		</table>
	</div>
	<script type="text/javascript">
		//选择产品经理
		function selectManager(){
			dlg_idx=1;
			//获取数据
			$('#dg_user').datagrid({
				url: "//cm/cmProductInfoAction!getUserList.do",
				queryParams:{ roleEnglishName : "cpjl" }	
			});
			
			$('#dlg_addPerson').dialog('open');
		}
		//选择交易主管
		function selectTradeManager(){
			dlg_idx=2;
			
			//获取数据
			$('#dg_user').datagrid({
				url: "//cm/cmProductInfoAction!getUserList.do",
				queryParams:{ roleEnglishName : "jyzg" }	
			});
			$('#dlg_addPerson').dialog('open');
		}
		//选择风控专员
		function selectRiskManager(){
			dlg_idx=3;
			
			//获取数据
			$('#dg_user').datagrid({
				url: "//cm/cmProductInfoAction!getUserList.do",
				queryParams:{ roleEnglishName : "fkzy" }	
			});
			$('#dlg_addPerson').dialog('open');
		}
		//选择划拨专员
		function selectTransferManager(){
			dlg_idx=4;
			
			//获取数据
			$('#dg_user').datagrid({
				url: "//cm/cmProductInfoAction!getUserList.do",
				queryParams:{ roleEnglishName : "hbzy" }	
			});
			$('#dlg_addPerson').dialog('open');
		}
		//选择会计专员
		function selectAccounting(){
			dlg_idx=5;
			
			//获取数据
			$('#dg_user').datagrid({
				url: "//cm/cmProductInfoAction!getUserList.do",
				queryParams:{ roleEnglishName : "kj" }	
			});
			$('#dlg_addPerson').dialog('open');
		}
		// 服务接口的信息 
		var orderUrl ="${SmManager.getOrderUrl()}";//重要操作的服务url
		//var orderUrl = 'http://218.106.145.164:9008/';
		var wsUrl = "${SmManager.getWsUrl() }";//行情url
		/*
		% if debugFlag:
            orderUrl = 'http://192.168.15.25:9008/';
            wsUrl = "ws://192.168.15.25:9009/";

		% endif
        */
		var requestId = '1';
		
		var saveType = "";
		var date = "";
		
		function businessService(param, callfun) {
			console.debug("请求参数 " + JSON.stringify(param));
			$.ajax({
				type : 'get',
				async: true,
				timeout:5000, 
				url : orderUrl,
				data : param,
				cache : false,
				dataType : 'jsonp',
				jsonp: "callback",
				jsonpCallback:"callback",
				success : function (data) {console.debug("接收服务返回成功" );callfun(data);},
				error : function (e) {
					alert("请求业务服务失败!");
					/* console.info("e : " + e.message);
					console.info("e : " + e.name);
					console.info("e : " + e.description);
					console.info("e : " + e.number);
					console.info("e : " + e.fileName);
					console.info("e : " + e.stack); */
				}
			});
		}
	    //查询按钮操作
		$('#search_btn').bind('click', function() {
			//alert('search_btn click');
			$('#dg').datagrid({
				pageNumber:1,
				url: "/cm/cmProductInfoAction!queryListJson.do",
				queryParams:{
                    //search_product_name : $('#search_product_name').textbox('getValue')
                    search_product_name : $('#search_product_id').combobox('getText')
				}	
			});
		});
	    //导出excel
        $('#export_btn').bind('click', function (){
		    //alert("export.");
            // 提交表单
            $('#file_form').form('submit', {
                url:"/cm/export/export_excel",
                success : function(data) {
                //alert("download");
                }
            });
		});
		//上传文件
		$('#upload_btn').bind('click', function (){
		    //alert("upload_btn.");
		    $('#file_form').form('submit', {
                url:"/cm/export/file_upload",
                beforeSend: function(xhr, settings){
                    var csrftoken = $.cookie('csrftoken');
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
                },
                success : function(data) {
                }
            });
		});
		//下载文件
		$('#download_btn').bind('click', function (){
		    //alert("download_btn.");
			// 提交表单
            $('#file_form').form('submit', {
                url:"/cm/export/file_download",
                success : function(data) {
                //alert("download");
                }
            });
		});
		//发送邮件
        $('#sendemail_btn').bind('click', function (){
        $('#dlg_sendEmail_').dialog('open');
        })
        function send_email(){
        $('#sendEmail_').form('submit', {
                url:"/cm/export/send_email",
                success : function(data) {
                alert("发送成功");
                }
            });
        $('#dlg_sendEmail_').dialog('close');
        }
		/////
		var toolbar = [ {
			text : '新增',
			iconCls : 'icon-add',
			handler : function() {
				//alert('add');
				saveType = '1';
				$('#ff').form('clear')
				$("#status").textbox('setValue','0');
				$("#status").textbox('setText','停止');
				$("#size_").textbox('setValue', '0');
				console.info("size_: " +$("#size_").numberbox('getValue'));
				$('#dlg_add').dialog('open');
			}
		}/* , {
			text : '删除',
			iconCls : 'icon-remove',
			handler : function() {
				var selected = getSelected();
				if (selected == "") {
					alert("请选择要删除的记录");
					return;
				} else {
					deleteData(selected);
				}
			} 
		} */];
		
		
		// 目标产品 id 
		var destClientId = '';
		
		// 增加规模
		function add_money(){
			console.info("destClientId: " + destClientId);
			if($('#addSize_ input').val() > 10000000000000000){
				alert('新增规模不可以超过10000000000000000万哦！！！');
				return;
			}
			if($('#addSize_ input').val() != ''){
				businessService({//源id：外部，目的id：产品
					requestId : requestId, //0 请求号
					funcId : '20', //1 功能号  char
					productId : destClientId, // 2 产品号
					srcClientType : 3, // 源客户类型  --1是产品， 2是投顾, 3是外部，其他出错
					destClentType : 1, // 目标客户类型  --1是产品， 2是投顾, 3是外部，其他出错
					destClientId : destClientId, //目标产品id
					transferCashNum : $('#addSize_ input').val() //转账金额
				}, function (data) {
					if (data.isSuccess == 'Y') {
						alert('新增规模成功');
						$('#dg').datagrid('reload');
					} else {
						alert ("新增规模失败 : \n错误码: " + JSON.stringify(data.isSuccess));
					}
				});
				//alert("链接超时");
				closeAddSize_Form();
		    	
		    }
		    else{ alert('请输入要增加的金额'); }
		}
		
		
		// 减少规模
		function remove_money(){
			if($('#removeSize_ input').val() != ''){
				businessService({//源id：产品，目的id：外部
					requestId : requestId, //0 请求号
					funcId : '20', //1 功能号  char
					productId : destClientId, // 2 产品号
					srcClientType : 1, // 源客户类型  --1是产品， 2是投顾, 3是外部，其他出错
					destClentType : 3, // 目标客户类型  --1是产品， 2是投顾, 3是外部，其他出错
					srcClientId : destClientId, //源产品id
					transferCashNum : $('#removeSize_ input').val() //转账金额
				}, function (data) {
					if (data.isSuccess == 'Y') {
						alert( '减少规模成功');
						$('#dg').datagrid('reload');
					} else {
						alert ("减少规模失败 : \n错误码: " + JSON.stringify(data.isSuccess));
					}
				});
		    	closeRemoveSize_Form();
		    }
		    else{ alert('请输入要减少的金额'); }
		}

		function getSelected() {
			var selected = "";
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				selected = row.product_id;
			}
			return selected;
		}

		function submitForm() {
			if (!$("#ff").form('validate')) {
				alert('重新填写');
				return;
			}
			var size_ = $("#size_").textbox('getValue');
			/* if (size_ >100000000 && saveType == '1') {
				alert('初始规模不可以超过100000000万哦！！！');
				return;
			} */
			//console.info(typeof(size_));
			if (size_ >100000000) {
				alert('初始规模不可以超过100000000万哦！！！');
				return;
			} 
			var formParam = $("#ff").serialize();//序列化表格内容为字符串
			if(date == undefined){
				//date = "2015-06-06 20:10:03"
				var curr_time = new Date();
				date = curr_time.getFullYear()+"-";
				date += curr_time.getMonth()+1+"-";
				date += curr_time.getDate()+"-";
				date += curr_time.getHours()+":";
				date += curr_time.getMinutes()+":";
				date += curr_time.getSeconds();
			}
			$.ajax({
				type : 'get',
				url : '/cm/cmProductInfoAction!saveData.do?date=' + date,
				data : formParam,
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (data.code=='1') {
						alert("操作成功");
						/* $('#dg').datagrid('reload');*/
						var curr_product_id = $('#search_product_id').combobox('getValue');
						
						if(data.isModify == false){
							$("#search_product_id").combobox({
								url : '/cm/cmProductInfoAction!getComoboValues.do?search_type=1'
							})
						}
						
						$("#search_product_id").combobox('select', curr_product_id);
						$('#dg').datagrid({
							pageNumber:1,
							url: "/cm/cmProductInfoAction!queryListJson.do",
							queryParams:{
			                    search_product_name : $('#search_product_id').combobox('getText')
							}	
						});
						closeForm();
					}else{
						alert(data.msg);
					}

					/* alert("操作成功");
					date = "";
					//window.location.reload();
					$('#dg').datagrid('reload');
					closeForm(); */
				}
			});
		}

		
		function loadFF(row, product_id) {
			$.ajax({
				type : 'get',
				url : '/cm/cmProductInfoAction!loadData.do?product_id=' + product_id,
				data : {},
				cache : false,
				dataType : 'json',
				success : function(data) {
					$('#ff').form('clear');
					$('#dlg_add').dialog('open');
                    $("#product_name").textbox('setValue', data.product_name);
                    $("#manager_id").textbox('setValue', data.manager_id);
                    $("#size_").textbox('setValue', data.size_);
                    $("#status").textbox('setValue', data.status);
                    $("#trade_manager_id").textbox('setValue', data.trade_manager_id);
                    $("#accounting_id").textbox('setValue', data.accounting_id);
                    $("#risk_manager_id").textbox('setValue', data.risk_manager_id);
                    $("#transfer_id").textbox('setValue', data.transfer_id);
                    $("#sh_a_account").textbox('setValue', data.sh_a_account);
                    $("#sz_a_account").textbox('setValue', data.sz_a_account);
                    $("#money_account").textbox('setValue', data.money_account);
                    $("#account_passwd").textbox('setValue', data.account_passwd);
                    //$("#re_account_passwd").textbox('setValue', data.account_passwd);
                    $("#fee_rate").textbox('setValue', data.fee_rate);

					$("#product_id").val(data.product_id);
					
					$("#product_name").textbox('setText', row.product_name);
		            $("#size_").textbox('setText', row.size_);
		            $("#status").textbox('setText', row.status);
					$('#manager_id').textbox('setText', row.manager_id);
					$('#trade_manager_id').textbox('setText', row.trade_manager_id);
					$('#risk_manager_id').textbox('setText', row.risk_manager_id);
					$('#accounting_id').textbox('setText', row.accounting_id); 
					$('#transfer_id').textbox('setText', row.transfer_id); 
					$("#sh_a_account").textbox('setText', row.sh_a_account);
		            $("#sz_a_account").textbox('setText', row.sz_a_account);
		            $("#money_account").textbox('setText', row.money_account);
		            $("#account_passwd").textbox('setText', row.account_passwd);
		            //$("#re_account_passwd").textbox('setText', row.account_passwd);
		            $("#fee_rate").numberbox('setText', row.fee_rate);
					console.info(row);
					console.info(row.manager_id);
				}
			});
			
		}

		function closeForm() {
			$('#ff').form('clear');
			$('#dlg_add').dialog('close');
		}
		function closeAddSize_Form(){
			$('#addSize_').form('clear');
			$('#dlg_addSize_').dialog('close');		
		}
		function closeSendEmail_form(){
			$('#sendEmail_').form('clear');
			$('#dlg_sendEmail_').dialog('close');
		}
		function closeRemoveSize_Form(){
			$('#removeSize_').form('clear');
			$('#dlg_removeSize_').dialog('close');		
		}
		function closeAddPerson_Form(){
			//$('#').form('clear');
			$('#dlg_addPerson').dialog('close');		
		}		

		function deleteData(product_id) {
			var yz = $.ajax({
				type : 'get',
				url : '/cm/cmProductInfoAction!deleteData.do?product_id=' + product_id,
				data : {},
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (data) {
						$("#search_product_id").combobox('reload');
						alert("操作成功");
						//window.location.reload();
						$('#dg').datagrid('reload');
						closeForm();
					}
				},
				error : function() {
					alert("操作异常");
					return;
				}
			});
		}

		function formatOper(val, row, index) {
			var value='<a href="#" onclick="modifyData(' + index + ')">修改</a>&nbsp&nbsp&nbsp\
						<a href="#" onclick="addSize_(' + index + ')">规模新增</a>&nbsp&nbsp&nbsp\
						<a href="#" onclick="removeSize_(' + index + ')">规模减少</a>';
			//获取到改行的投顾账户的状态
			if(row.status == '激活'){
				value+='&nbsp&nbsp&nbsp <a href="#" onclick="accountPause(' + index + ', ' + row.product_id + ')">账户停止</a>';
			}
			if(row.status == '停止'){
				value+='&nbsp&nbsp&nbsp <a href="#" onclick="accountActive(' + index + ', ' + row.product_id + ')">账户激活</a>';
			}
			return value;
		}

		function modifyData(index) {
			saveType = '2';
			var re_account_passwd=document.getElementById('re_account_passwd');
			if(re_account_passwd){
			   if(re_account_passwd.style.display=='inline'){
			   		re_account_passwd.style.display='none';
			   }
			}
			/*
			re_account_passwd = $('#re_account_passwd')
			if(re_account_passwd.style.display=='block'){
			   re_account_passwd.style.display='none';
			} else{
			   re_account_passwd.style.display='block';
			} */
						
			$('#dg').datagrid('selectRow', index);// 关键在这里  
			var row = $('#dg').datagrid('getSelected');
			date = row.create_date;
			if (row) {
				loadFF(row, row.product_id);
			}
		}
		
		//账户停止方法
		function accountPause(rowIndex, product_id){
			//product_id = $('#search_product_id').combobox('getValue');
			console.info("product_id: " + product_id);
			$.ajax({
				type : 'get', 
				url : '/cm/cmProductInfoAction!updateStatusToPause.do?search_value=' + product_id,
				success : function(data) {
					if(data){
						$('#dg').datagrid(
							'updateRow',
							{
								index:rowIndex,
								row:{status:"停止"}
							});
						}
					
				}
			});

		}
		//账户激活方法
		function accountActive(rowIndex, product_id){
			//product_id = $('#search_product_id').combobox('getValue');
			console.info("product_id: " + product_id);
			$.ajax({
				type : 'get',
				url : '/cm/cmProductInfoAction!updateStatusToActive.do?search_value=' + product_id,
				success : function(data) {
					if(data){
						$('#dg').datagrid(
							'updateRow',
							{
								index:rowIndex,
								row:{status:"激活"}
							});
						}
					
				}
			});

		}
		
		function addSize_(index) {
			$('#dg').datagrid('selectRow', index);// 关键在这里  
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				destClientId = row.product_id;
				$('#dlg_addSize_').dialog('open');
				//loadFF(row.product_id);
			}
		}		

		function removeSize_(index) {
			$('#dg').datagrid('selectRow', index);// 关键在这里  
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				destClientId = row.product_id;
				$('#dlg_removeSize_').dialog('open');
				//loadFF(row.product_id);
			}
		}
		
		function formatUserOper(val, row, index) {
			return '<a href="#" style="align:center" onclick="selectUser(' + index + ')">选择</a>&nbsp&nbsp&nbsp&nbsp';
		}
		
		function selectUser(index){
			$('#dg_user').datagrid('selectRow', index);// 关键在这里  
			var rowUser = $('#dg_user').datagrid('getSelected');
			
			if(dlg_idx == 1){//产品经理
				$('#manager_id').textbox('setValue', rowUser.user_id);
				$('#manager_id').textbox('setText', rowUser.user_name);
				console.info($('#manager_id').textbox('getText'));
				console.info($('#manager_id').textbox('getValue'));
			}
			else if(dlg_idx == 2){ //交易主管
				$('#trade_manager_id').textbox('setValue', rowUser.user_id);
				$('#trade_manager_id').textbox('setText', rowUser.user_name);
				
			}
			else if(dlg_idx == 3){//风控专员
				$('#risk_manager_id').textbox('setValue', rowUser.user_id);
				$('#risk_manager_id').textbox('setText', rowUser.user_name);
			}
			else if(dlg_idx == 4){//划拨专员
				$('#transfer_id').textbox('setValue', rowUser.user_id);
				$('#transfer_id').textbox('setText', rowUser.user_name);
			}
			else if(dlg_idx == 5){//会计
				$('#accounting_id').textbox('setValue', rowUser.user_id);
				$('#accounting_id').textbox('setText', rowUser.user_name);
			}
			   
			//
			$('#dlg_addPerson').dialog('close');
		}
		
		
		
		////////
		$(function() {
			//界面统一设置
			//$("#dg").datagrid('hideColumn', 'product_id');
			$("#dg").datagrid('hideColumn', 'trade_manager_id');
			$("#dg").datagrid('hideColumn', 'risk_manager_id');
			$("#dg").datagrid('hideColumn', 'transfer_id');
			$("#dg").datagrid('hideColumn', 'accounting_id'); 
			$("#dg").datagrid('hideColumn', 'sh_a_account');
			$("#dg").datagrid('hideColumn', 'sz_a_account');
			$("#dg").datagrid('hideColumn', 'money_account');
			$("#dg").datagrid('hideColumn', 'fee_rate'); 
			$("#dg").datagrid('hideColumn', 'account_passwd'); 
			
			
	                    
			$('#dlg_add').dialog('close');
			$('#dlg_addSize_').dialog('close');
			$('#dlg_removeSize_').dialog('close');
			$('#dlg_addPerson').dialog('close');
			$('#dlg_sendEmail_').dialog('close');

			//扩展验证
			initValidate();

			//初始化界面设置
			$.ajax({
				type : 'get',
				url : '//cm/cmProductInfoAction!getInitValue.do',
				cache : false,
				dataType : 'json',
				success : function(data) {
					
					initUI(data);
				}
			});
			//下拉联动配置
			$("#search_product_id").combobox({
				url : '//cm/cmProductInfoAction!getComoboValues.do?search_type=1',
				onLoadSuccess : function(data){
					try {
						//alert("data[0].product_id : " + data[0].product_id);
						$("#search_product_id").combobox('select',data[0].product_id);
						$('#dg').datagrid({
							pageNumber:1,
							url: "//cm/cmProductInfoAction!queryListJson.do",
							queryParams:{
								search_product_name : $('#search_product_id').combobox('getText')
							}	
						});
					} catch (e) {
						//alert("数据库中没有产品");
					}
				}
			})
				
		
			$("#search_product_id").combobox('reload');
			// 业务接口函数
			
	});
	</script>

</body>
</html>
% endif